import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:top_foundation/utils/ex/color.dart';
import 'package:top_foundation/utils/theme/theme.dart';
import 'package:whale/helper/utils/util.dart';
import 'package:whale/pages/casstle_demo/casstle_demo_2/index.dart';
import 'package:whale/pages/casstle_demo/casstle_demo_2/view.dart';
import 'package:whale/pages/common/video_full_player/index.dart';
import 'package:whale/pages/msg_page/sub/anchor_demo/index.dart';
import 'package:whale/pages/msg_page/sub/carousel_text_demo/index.dart';
import 'package:whale/pages/msg_page/sub/chart_demo/index.dart';
import 'package:whale/pages/msg_page/sub/date_picker_demo/index.dart';
import 'package:whale/pages/msg_page/sub/http_test_demo/index.dart';
import 'package:whale/pages/msg_page/sub/map/index.dart';
import 'package:whale/pages/msg_page/sub/push.dart';
import 'package:whale/pages/msg_page/sub/rich_text_field_demo/index.dart';
import 'package:whale/pages/msg_page/sub/screen_shot_demo/index.dart';
import 'package:whale/pages/msg_page/sub/share_demo/index.dart';
import 'package:whale/pages/msg_page/sub/tab_demo/index.dart';
import 'package:whale/pages/msg_page/sub/tabbar_demo/index.dart';
import 'package:whale/pages/msg_page/sub/usually_view_demo/index.dart';
import 'package:whale/pages/msg_page/sub/usually_view_demo/view.dart';
import 'package:whale/pages/msg_page/sub/video_player_demo/video_player_list_demo/index.dart';

import '../audio/index.dart';
import '../casstle_demo/index.dart';
import '../download_demo/index.dart';
import '../home/main/widgets/pop_page.dart';
import '../refresh_demo/index.dart';
import 'index.dart';
import 'widgets/widgets.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

class MsgPagePage extends StatelessWidget {
  MsgPagePage({Key? key}) : super(key: key);
  final controller = Get.put(MsgPageController());

  // 主视图
  Widget _buildView() {
    final list = [
      Textcell(
          text: '录音',
          onTap: () {
            Get.to(() => AudioPage(), binding: AudioBinding());
          }),
      Textcell(
          text: '单页面刷新',
          onTap: () {
            Get.to(() => RefreshDemoPage(), binding: RefreshDemoBinding());
          }),
      Textcell(
          text: '常规多页面及刷新',
          onTap: () {
            Get.to(() => TabDemoPage(), binding: TabDemoBinding());
          }),
      Textcell(
          text: '多页面嵌套及刷新样式1',
          onTap: () {
            Get.to(() => CasstleDemo_2Page(), binding: CasstleDemo_2Binding());
          }),
      Textcell(
          text: '多页面嵌套及刷新样式2',
          onTap: () {
            Get.to(() => CasstleDemoPage(), binding: CasstleDemoBinding());
          }),
      Textcell(
          text: '转场动画',
          onTap: () {
            Get.to(() => PushAnimatePage());
          }),
      Textcell(
          text: '下载',
          onTap: () {
            Get.to(() => DownloadDemoPage(), binding: DownloadDemoBinding());
          }),
      Textcell(
          text: '跑马灯',
          onTap: () {
            Get.to(() => CarouselTextDemoPage(),
                binding: CarouselTextDemoBinding());
          }),
      // Textcell(
      //     text: '地图',
      //     onTap: () {
      //       Get.to(() => MapPage(), binding: MapBinding());
      //     }),
      Textcell(
          text: '时间选择',
          onTap: () {
            Get.to(() => DatePickerDemoPage(),
                binding: DatePickerDemoBinding());
          }),
      Textcell(
          text: '图表📈',
          onTap: () {
            Get.to(() => ChartDemoPage(), binding: ChartDemoBinding());
          }),
      Textcell(
          text: '分享',
          onTap: () {
            Get.to(() => ShareDemoPage(), binding: ShareDemoBinding());
          }),
      Textcell(
          text: '禁止屏幕截图录像',
          onTap: () {
            Get.to(() => ScreenShotDemoPage(),
                binding: ScreenShotDemoBinding());
          }),
      Textcell(
          text: '接口测试',
          onTap: () {
            Get.to(() => HttpTestDemoPage(), binding: HttpTestDemoBinding());
          }),
      Textcell(
          text: '富文本输入框',
          onTap: () {
            Get.to(() => RichTextFieldDemoPage(),
                binding: RichTextFieldDemoBinding());
          }),
      Textcell(
          text: '视频横屏播放',
          onTap: () {
            Get.to(() => VideoFullPlayerPage(),
                binding: VideoFullPlayerBinding(),
                arguments: {
                  'title': '视频标题',
                  'url':
                      'https://ocfan.tt90.cc/pro/uploadfile/20240618/661612209129975808.mp4'
                });
          }),
      Textcell(
          text: '锚点绑定',
          onTap: () {
            Get.to(
              () => AnchorDemoPage(),
              binding: AnchorDemoBinding(),
            );
          }),
      Textcell(
          text: '分段控制器TabBar',
          onTap: () {
            Get.to(
              () => TabbarDemoPage(),
              binding: TabbarDemoBinding(),
            );
          }),

      Textcell(
          text: '常用组件',
          onTap: () {
            Get.to(
              () => UsuallyViewDemoPage(),
              binding: UsuallyViewDemoBinding(),
            );
          }),
      Textcell(
          text: '视频播放',
          onTap: () {
            Get.to(
              () => VideoPlayerListDemoPage(),
              binding: VideoPlayerListDemoBinding(),
            );
          }),
    ];
    return MasonryGridView.count(
      crossAxisCount: 4,
      mainAxisSpacing: 4,
      crossAxisSpacing: 4,
      itemBuilder: (context, index) {
        final double s = max(50, Random().nextDouble() * 200);
        return SizedBox(
          width: s,
          height: s,
          child: list[index],
        );
      },
      itemCount: list.length,
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MsgPageController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("msg")),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}

class Textcell extends StatelessWidget {
  const Textcell({
    super.key,
    required this.text,
    required this.onTap,
  });
  final String text;
  final VoidCallback onTap;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 12.r),
        // height: 50.r,
        alignment: Alignment.center,
        decoration: BoxDecoration(
          border: Border(
            bottom: ITheme.borderSide,
          ),
          color: ColorEx.random,
        ),
        child: Text(
          text,
          style: TextStyle(
            color: Colors.white,
            fontSize: 15.sp,
          ),
        ),
      ),
    );
  }
}
